/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ACH.app.util;

/**
 *
 * @author adriancruz11c
 */
public class General {
        public static double matchArrays(String []a1, String []a2){
        int cycle=0,matches=0;
        boolean ca1=true;
        double result=0.0;
        cycle=a1.length;
        if (cycle>a2.length){
            cycle=a2.length;
            ca1=false;
        }
        if (ca1)    {
            for (int i=0; i<cycle; i++){
                if (isEqualElems(a2, a1[i]))
                    matches++;
            }
        }
        else{
            for (int i=0; i<cycle; i++){
                if (isEqualElems(a1, a2[i]))
                    matches++;
            }
        }
        System.out.println("matches: "+matches+"  cycle: "+cycle);
        //int diff=cycle-matches;    
        if (cycle>0)
        result= (double)matches/cycle;     
        else
            result =0.0;
        System.out.println("Result:"+result+" ==" + (double)matches/cycle);
        return result;
                
    }
    public static boolean isEqualElems(String []a1, String a2){
        boolean result=false;
        if (a1.length==1)
            if (a1[0]==null || a1[0].equalsIgnoreCase(""))
                return false;
        for (int i=0; i<a1.length; i++){
            if(a1[i].equalsIgnoreCase(a2))
                return true;
        }
        return result;
    }
}
